package cn.springsoter.core.log4j2;

import java.util.Properties;

import org.springframework.boot.builder.SpringApplicationBuilder;

import cn.springsoter.core.launch.service.ILauncherService;

/**
 * 日志启动器
 *
 * @author kevin
 */
public class LogLauncherServiceImpl implements ILauncherService {

	@Override
	public void launcher(SpringApplicationBuilder builder, String profile, boolean isLocalDev) {
		Properties props = System.getProperties();
		props.setProperty("logging.config", String.format("classpath:log4j2/log4j2_%s.xml", profile));
		// RocketMQ-Client 4.2.0 Log4j2 配置文件冲突问题解决：https://www.jianshu.com/p/b30ae6dd3811
		props.setProperty("rocketmq.client.log.loadconfig", "false");
		// RocketMQ-Client 4.3 设置默认为 slf4j
		props.setProperty("rocketmq.client.logUseSlf4j", "true");
		// 将全部的 System.err 和 System.out 替换为log
//		if (!isLocalDev) {
//		System.setOut(LogPrintStream.out());
//		System.setErr(LogPrintStream.err());
//		}
	}

}
